# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Aaron, phrakture, Griffin <aaron@archlinux.org>
# Contributor: erkaN kaplaN <erkan@linux-sevenler.org>
# Contributor: Alexsandr Pavlov <kidoz at mail dot ru>

pkgname=gwget
pkgver=1.0.4
pkgrel=19
pkgdesc='Download manager for GNOME'
arch=('loong64' 'x86_64')
url='https://gitlab.gnome.org/Archive/gwget'
license=('GPL')
depends=('gtk3' 'libnotify' 'wget')
makedepends=('intltool' 'imagemagick')
source=("https://download.gnome.org/sources/$pkgname/${pkgver%.*}/$pkgname-$pkgver.tar.bz2"
        'gwget.appdata.xml'
        'gwget-1.0.4-notify-0.7.patch'
        'gwget-1.0.4-glib-2.32.patch'
        'drop-libgnomeui.patch'
        'gtk3-port.patch'
        'wget.patch'
        'various-fixes.patch'
        'gsettings-port.patch')
sha256sums=('a65b2b2b3befb6cf34a697a13111b35498a6d63f9a9b048a22b8654f35ef643f'
            'd65a5d86ea3cb80f6058a2134010137a3ff465373a028f983a83065d0267368e'
            '84efbbea9c2a91c60288edb67264bbdb4ec2c579cf95b3baa8282040a1b65c76'
            '319c4795d0034c4adacf302db697d966ca228fc1bbe9778af9dadcfb0c2531c8'
            '019fae87e984d22cd1bbe7b3fc064c936a76658ef98cbf96f7ba1c10678ac585'
            'e85e3eeb091bd88bf11866c6256cd36c375f456d07599a9e6a15400fa26546f8'
            '3900defbf161a657ef3968a0aa1df27605e1fbf6fc34d0fcba748ce274fa4f3c'
            '9e45add4dbdaa397de4aa985887e722e97541fbc59cec4dfa82287efc695ee87'
            'a62fdc10d63772b5d484192184812265574644518e31cb573090b1c657e28ef5')

prepare() {
  cd $pkgname-$pkgver

  # https://bugzilla.gnome.org/show_bug.cgi?id=634170
  patch -Np1 -i ../gwget-1.0.4-notify-0.7.patch

  # https://bugzilla.gnome.org/show_bug.cgi?id=665286
  patch -Np1 -i ../gwget-1.0.4-glib-2.32.patch

  # https://bugzilla.gnome.org/show_bug.cgi?id=671759
  patch -Np1 -i ../drop-libgnomeui.patch

  # Port to GTK 3
  patch -Np1 -i ../gtk3-port.patch

  # Fix with recent wget versions
  patch -Np1 -i ../wget.patch

  # Set fallback destination path properly, don't try to start downloading existing URL
  patch -Np1 -i ../various-fixes.patch

  # Port to GSettings
  patch -Np1 -i ../gsettings-port.patch

  # Install icon into icons directory
  sed -i 's|$(datadir)/pixmaps|$(datadir)/icons/hicolor/48x48/apps|' pixmaps/Makefile.am
  convert pixmaps/gwget-large.png +set date:create +set date:modify -background none -extent 200x200 pixmaps/gwget-large.png
  convert pixmaps/gwget-large.png +set date:create +set date:modify -resize 64x64 -alpha on pixmaps/gwget-64.png
  convert pixmaps/gwget-large.png +set date:create +set date:modify -resize 128x128 -alpha on pixmaps/gwget-128.png

  autoreconf -fi
}

build() {
  cd $pkgname-$pkgver
  CFLAGS+=' -fcommon' # https://wiki.gentoo.org/wiki/Gcc_10_porting_notes/fno_common
  ./configure --prefix=/usr \
              --disable-schemas-compile
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  install -Dm644 pixmaps/gwget-64.png "$pkgdir/usr/share/icons/hicolor/64x64/apps/gwget.png"
  install -Dm644 pixmaps/gwget-128.png "$pkgdir/usr/share/icons/hicolor/128x128/apps/gwget.png"
  install -Dm644 ../$pkgname.appdata.xml "$pkgdir/usr/share/metainfo/$pkgname.appdata.xml"
}
